import pandas as pd

# 创建DataFrame
df = pd.DataFrame({
    "语文": [77, 59, 46],
    "数学": [70, 88, 49],
    "英语": [79, 90, 32],
    "Length": [8, 6, 5],
    "Width": [3, 4, 2]
}, index=["a1", "a2", "a3"])

print("原始DataFrame:\n", df)

# 选择多个指定列
df_multiple_cols = df[["语文", "英语"]]
print("\n选择语文和英语列:\n", df_multiple_cols)

# 选择单个指定列（两种方式）
df_single_col_1 = df["语文"]
df_single_col_2 = df.语文
print("\n选择语文列（第一种方式）:\n", df_single_col_1)
print("\n选择语文列（第二种方式）:\n", df_single_col_2)

# 使用filter通过正则表达式选择列
df_filter_cols = df.filter(regex='语|数')
print("\n通过正则表达式选择列名包含'语'或'数'的列:\n", df_filter_cols)

# 使用query筛选行
df_query_1 = df.query('Length > 7')
print("\n筛选出Length > 7的行:\n", df_query_1)

df_query_2 = df.query('Length > 7 and Width < 8')
print("\n筛选出Length > 7且Width < 8的行:\n", df_query_2)

# 假设添加Name列用于演示str.startswith
df['Name'] = ['abc1', 'def2', 'ghi3']
df_query_3 = df.query("Name.str.startswith('abc')", engine="python")
print("\n筛选出Name列以'abc'开头的行:\n", df_query_3)